package com.apes.framework.plugin.condition.model;

import com.apes.framework.jpa.ApesBean;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.condition.PricingProcedureContext;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Map;

/**
 * 功能：存取顺序明细
 *
 * @author xul
 * @create 2018-11-06 17:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = AccessSequencesItem.CONST_TABLE_NAME)
public class AccessSequencesItem implements ApesBean {
    public static final String CONST_TABLE_NAME = "tech_access_sequences_item";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "存取顺序")
    @Comment("编号")
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "access_sequences_id", nullable = false, referencedColumnName = "id")
    @Comment("存取顺序")
    private AccessSequences accessSequences;

    @Column(name = "step", nullable = false)
    @Comment("顺序、步骤")
    private int step;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "condition_table_id", referencedColumnName = "id", nullable = false)
    @Comment("条件表")
    private ConditionTable conditionTable;

    public <T> T process(final PricingProcedureContext context) {
        return conditionTable.findConditionRecord(context);
    }
}
